/**
 *  通过dispatch('action',param) -> Action --commit--> mutation  --> state
 *  
 * =================================
 * mapState（mapGetters） 的使用
 * 
 * import {mapState} from 'vuex'
 * ...mapState({newName:'stateName'})
 * or
 * ...mapState(['stateName'])
 * 
 * ================================
 * mapMutations (mapActions) 的使用
 * import {mapMustations} from 'vuex'
 * 
 * ...mapMutations({newmutationName:'setUserInfo'})
 * or
 * ...mapmutations(['setUserInfo'])
 */
const state = () => ({
  userInfo: null,
  wxAdmin:'',
  checkedAdmin:false,
  token:'',
})
const getters = {
  userInfo: (state) => state.userInfo,
  wxAdmin: (state) => state.wxAdmin,
  checkedAdmin: (state) => state.checkedAdmin,
  token: (state) => state.token,
}

const actions = {
  getUserInfo(content,state) {
	if(state && state.wxAdmin){
		let wxAdminObj = JSON.parse(state.wxAdmin)
		content.commit('setWxAdmin', wxAdminObj.type)
	}
    content.commit('setUserInfo', state)
  },
  getWxAdmin(content,state){
	   content.commit('setWxAdmin', state)
  },
  getCheckedAdmin(content,state){
	   content.commit('setCheckedAdmin', state)
  },
  setToken(content,state){
	  content.commit('setTokenMutation', state)
  }
  
}

const mutations = {
  setUserInfo(state, value) {
    state.userInfo = value
  },
  setWxAdmin(state, value) {
    state.wxAdmin = value
  },
  setCheckedAdmin(state, value) {
    state.checkedAdmin = value
  },
  setTokenMutation(state, value){
	  state.token = value
  }
}
export default { state, getters, mutations, actions }
